angular.module('meIntegratListServices', [])

  .factory('IntegratList', function ($resource, $rootScope, ENV, Storage) {

    //设置访问接口路径
    var APIUrl = ENV.api;
    //var memberId = Storage.get("member").member_id;

    //访问获取用户信息的接口
    var integratListResource = $resource(APIUrl + "mePointShop/getPointShopList.do");
    var exchangeWineResource = $resource(APIUrl + "mePointShop/exchangeWine.do");

    var integratList;
    var exchangeResult;

    return {

      //获取积分商城的内容
      getIntegratList: function () {
        integratListResource.save({}, function (data) {
          integratList = data;
          $rootScope.$broadcast('Me.getIntegratList');
        });

      },

      getIntegratListJson: function () {
        return integratList;
      },

      //获取是否可以兑换的结果
      getExchangeResult: function (productId,memberId) {
        exchangeWineResource.save(
          {
            member_id: memberId,
            psp_id: productId
          },
          function (data) {
            exchangeResult = data;
            $rootScope.$broadcast('Me.getExchangeResult');
          });
      },

      getExchangeResultJson: function () {
        return exchangeResult;
      }

    }


  });
